<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>后台管理</title>
    <link rel="stylesheet" href="__STATIC__/js/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/css/login.css">
    <script src="__STATIC__/js/layui.js"></script>
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;background: #f2f2f2;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>后台管理系统</h2>
            <p></p>
        </div>
        <form class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="username"></label>
                <input type="text" name="username" id="username" lay-verify="required" placeholder="账号" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="password"></label>
                <input type="password" name="password" id="password" lay-verify="required" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="vercode"></label>
                        <input type="text" name="vercode" id="vercode" lay-verify="required" placeholder="验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="{:url('verify/index')}" id="captcha" alt="验证码" title="点击切换验证码">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="loginsubmit">登 录</button>
            </div>
        </form>
    </div>

</div>
<script>
    if (window != top) top.location.href = location.href;
    layui.use(['layer', 'form'], function () {
        var $ = layui.$, layer = layui.layer, form = layui.form;
        $("#captcha").click(function () {
            captcha();
        });

        function captcha() {
            var _scr = $("#captcha").attr('src');
            $("#captcha").attr('src', _scr.split('?')[0] + '?' + Math.random());
        }

        form.on('submit(loginsubmit)', function (data) {
            $.ajax({
                url: '{:url("passport/login")}',
                type: 'POST',
                dataType: 'json',
                data: data.field,
            })
                .done(function (res) {
                    layer.msg(res.msg, function () {
                        if (res.code == 0) {
                            $(data.elem).removeClass('layui-btn-disabled').text('登 录');
                            captcha();
                            $('form')[0].reset();
                        }
                        if (res.url != '') window.location.href = '{:url("index/index")}';
                    });
                })
                .fail(function () {
                    layer.msg('貌似出了点问题');
                })
                .always(function () {
                    $(data.elem).addClass('layui-btn-disabled').text('登录中...');
                });
            return false;
        });
    });
</script>
</body>
</html>